const { Sequelize, DataTypes, Op } = require("sequelize");
const sequelize = new Sequelize({
  dialect: "sqlite",
  storage: "./db.sqlite", //项目目录、安装目录
  query: { raw: true },
  logging: false,
});

//储物柜Locker
const Locker = sequelize.define("Locker", {
  BlId: DataTypes.INTEGER,
  DeviceId: DataTypes.TEXT,
  mainboardno: DataTypes.INTEGER,
  lockno: DataTypes.INTEGER,
  czh: {
    type: DataTypes.TEXT,
    defaultValue: "",
  },
  occupied: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
  },
});
const glLockers = [
  { BlId: 1, DeviceId: "001", mainboardno: 1, lockno: 1 },
  { BlId: 2, DeviceId: "001", mainboardno: 1, lockno: 2 },
  { BlId: 3, DeviceId: "001", mainboardno: 1, lockno: 3 },
  { BlId: 4, DeviceId: "001", mainboardno: 1, lockno: 4 },
  { BlId: 5, DeviceId: "001", mainboardno: 1, lockno: 5 },
  { BlId: 6, DeviceId: "001", mainboardno: 1, lockno: 6 },
  { BlId: 7, DeviceId: "001", mainboardno: 1, lockno: 7 },
  { BlId: 8, DeviceId: "001", mainboardno: 1, lockno: 8 },
  { BlId: 9, DeviceId: "001", mainboardno: 1, lockno: 9 },
  { BlId: 10, DeviceId: "001", mainboardno: 1, lockno: 10 },
  { BlId: 11, DeviceId: "001", mainboardno: 1, lockno: 11 },
  { BlId: 12, DeviceId: "001", mainboardno: 1, lockno: 12 },
  { BlId: 13, DeviceId: "001", mainboardno: 1, lockno: 13 },
  { BlId: 14, DeviceId: "001", mainboardno: 1, lockno: 14 },
  { BlId: 15, DeviceId: "001", mainboardno: 2, lockno: 1 },
  { BlId: 16, DeviceId: "001", mainboardno: 2, lockno: 2 },
  { BlId: 17, DeviceId: "001", mainboardno: 2, lockno: 3 },
  { BlId: 18, DeviceId: "001", mainboardno: 2, lockno: 4 },
  { BlId: 19, DeviceId: "001", mainboardno: 2, lockno: 5 },
  { BlId: 20, DeviceId: "001", mainboardno: 2, lockno: 6 },
  { BlId: 21, DeviceId: "001", mainboardno: 2, lockno: 7 },
  { BlId: 22, DeviceId: "001", mainboardno: 2, lockno: 8 },
  { BlId: 23, DeviceId: "001", mainboardno: 2, lockno: 9 },
  { BlId: 24, DeviceId: "001", mainboardno: 2, lockno: 10 },
  { BlId: 25, DeviceId: "001", mainboardno: 2, lockno: 11 },
  { BlId: 26, DeviceId: "001", mainboardno: 2, lockno: 12 },
  { BlId: 27, DeviceId: "001", mainboardno: 3, lockno: 1 },
  { BlId: 28, DeviceId: "001", mainboardno: 3, lockno: 2 },
  { BlId: 29, DeviceId: "001", mainboardno: 3, lockno: 3 },
  { BlId: 30, DeviceId: "001", mainboardno: 3, lockno: 4 },
  { BlId: 31, DeviceId: "001", mainboardno: 3, lockno: 5 },
  { BlId: 32, DeviceId: "001", mainboardno: 3, lockno: 6 },
  { BlId: 33, DeviceId: "001", mainboardno: 3, lockno: 7 },
  { BlId: 34, DeviceId: "001", mainboardno: 3, lockno: 8 },
  { BlId: 35, DeviceId: "001", mainboardno: 3, lockno: 9 },
  { BlId: 36, DeviceId: "001", mainboardno: 3, lockno: 10 },
  { BlId: 37, DeviceId: "001", mainboardno: 3, lockno: 11 },
  { BlId: 38, DeviceId: "001", mainboardno: 3, lockno: 12 },
  { BlId: 39, DeviceId: "001", mainboardno: 4, lockno: 1 },
  { BlId: 40, DeviceId: "001", mainboardno: 4, lockno: 2 },
  { BlId: 41, DeviceId: "001", mainboardno: 5, lockno: 1 },
  { BlId: 42, DeviceId: "001", mainboardno: 5, lockno: 2 },
  { BlId: 43, DeviceId: "001", mainboardno: 5, lockno: 3 },
  { BlId: 44, DeviceId: "001", mainboardno: 5, lockno: 4 },
  { BlId: 45, DeviceId: "001", mainboardno: 5, lockno: 5 },
  { BlId: 46, DeviceId: "001", mainboardno: 5, lockno: 6 },
  { BlId: 47, DeviceId: "001", mainboardno: 5, lockno: 7 },
  { BlId: 48, DeviceId: "001", mainboardno: 5, lockno: 8 },
  { BlId: 49, DeviceId: "001", mainboardno: 5, lockno: 9 },
  { BlId: 50, DeviceId: "001", mainboardno: 5, lockno: 10 },
  { BlId: 51, DeviceId: "001", mainboardno: 5, lockno: 11 },
  { BlId: 52, DeviceId: "001", mainboardno: 5, lockno: 12 },
  { BlId: 53, DeviceId: "001", mainboardno: 6, lockno: 1 },
  { BlId: 54, DeviceId: "001", mainboardno: 6, lockno: 2 },
];
const nnLockers = [
  { BlId: 1, DeviceId: "001", mainboardno: 1, lockno: 1 },
  { BlId: 2, DeviceId: "001", mainboardno: 1, lockno: 2 },
  { BlId: 3, DeviceId: "001", mainboardno: 1, lockno: 3 },
  { BlId: 4, DeviceId: "001", mainboardno: 1, lockno: 4 },
  { BlId: 5, DeviceId: "001", mainboardno: 1, lockno: 5 },
  { BlId: 6, DeviceId: "001", mainboardno: 1, lockno: 6 },
  { BlId: 7, DeviceId: "001", mainboardno: 1, lockno: 7 },
  { BlId: 8, DeviceId: "001", mainboardno: 1, lockno: 8 },
  { BlId: 9, DeviceId: "001", mainboardno: 1, lockno: 9 },
  { BlId: 10, DeviceId: "001", mainboardno: 1, lockno: 10 },
  { BlId: 11, DeviceId: "001", mainboardno: 1, lockno: 11 },
  { BlId: 12, DeviceId: "001", mainboardno: 1, lockno: 12 },
  { BlId: 13, DeviceId: "001", mainboardno: 1, lockno: 13 },
  { BlId: 14, DeviceId: "001", mainboardno: 1, lockno: 14 },
  { BlId: 15, DeviceId: "001", mainboardno: 2, lockno: 1 },
  { BlId: 16, DeviceId: "001", mainboardno: 2, lockno: 2 },
  { BlId: 17, DeviceId: "001", mainboardno: 2, lockno: 3 },
  { BlId: 18, DeviceId: "001", mainboardno: 2, lockno: 4 },
  { BlId: 19, DeviceId: "001", mainboardno: 2, lockno: 5 },
  { BlId: 20, DeviceId: "001", mainboardno: 2, lockno: 6 },
  { BlId: 21, DeviceId: "001", mainboardno: 2, lockno: 7 },
  { BlId: 22, DeviceId: "001", mainboardno: 2, lockno: 8 },
  { BlId: 23, DeviceId: "001", mainboardno: 2, lockno: 9 },
  { BlId: 24, DeviceId: "001", mainboardno: 2, lockno: 10 },
  { BlId: 25, DeviceId: "001", mainboardno: 2, lockno: 11 },
  { BlId: 26, DeviceId: "001", mainboardno: 2, lockno: 12 },
  { BlId: 27, DeviceId: "001", mainboardno: 2, lockno: 13 },
  { BlId: 28, DeviceId: "001", mainboardno: 2, lockno: 14 },
  { BlId: 29, DeviceId: "001", mainboardno: 3, lockno: 1 },
  { BlId: 30, DeviceId: "001", mainboardno: 3, lockno: 2 },
  { BlId: 31, DeviceId: "001", mainboardno: 3, lockno: 3 },
  { BlId: 32, DeviceId: "001", mainboardno: 3, lockno: 4 },
  { BlId: 33, DeviceId: "001", mainboardno: 3, lockno: 5 },
  { BlId: 34, DeviceId: "001", mainboardno: 3, lockno: 6 },
  { BlId: 35, DeviceId: "001", mainboardno: 3, lockno: 7 },
  { BlId: 36, DeviceId: "001", mainboardno: 3, lockno: 8 },
  { BlId: 37, DeviceId: "001", mainboardno: 3, lockno: 9 },
  { BlId: 38, DeviceId: "001", mainboardno: 3, lockno: 10 },
  { BlId: 39, DeviceId: "001", mainboardno: 3, lockno: 11 },
  { BlId: 40, DeviceId: "001", mainboardno: 3, lockno: 12 },
  { BlId: 41, DeviceId: "001", mainboardno: 3, lockno: 13 },
  { BlId: 42, DeviceId: "001", mainboardno: 3, lockno: 14 },
  { BlId: 43, DeviceId: "001", mainboardno: 4, lockno: 1 },
  { BlId: 44, DeviceId: "001", mainboardno: 4, lockno: 2 },
  { BlId: 45, DeviceId: "001", mainboardno: 4, lockno: 3 },
  { BlId: 46, DeviceId: "001", mainboardno: 4, lockno: 4 },
  { BlId: 47, DeviceId: "001", mainboardno: 4, lockno: 5 },
  { BlId: 48, DeviceId: "001", mainboardno: 4, lockno: 6 },
  { BlId: 49, DeviceId: "001", mainboardno: 4, lockno: 7 },
  { BlId: 50, DeviceId: "001", mainboardno: 4, lockno: 8 },
  { BlId: 51, DeviceId: "001", mainboardno: 4, lockno: 9 },
  { BlId: 52, DeviceId: "001", mainboardno: 4, lockno: 10 },
  { BlId: 53, DeviceId: "001", mainboardno: 4, lockno: 11 },
  { BlId: 54, DeviceId: "001", mainboardno: 4, lockno: 12 },
  { BlId: 55, DeviceId: "001", mainboardno: 4, lockno: 13 },
  { BlId: 56, DeviceId: "001", mainboardno: 4, lockno: 14 },
  { BlId: 57, DeviceId: "001", mainboardno: 5, lockno: 1 },
  { BlId: 58, DeviceId: "001", mainboardno: 5, lockno: 2 },
  { BlId: 59, DeviceId: "001", mainboardno: 5, lockno: 3 },
  { BlId: 60, DeviceId: "001", mainboardno: 5, lockno: 4 },
  { BlId: 61, DeviceId: "001", mainboardno: 5, lockno: 5 },
  { BlId: 62, DeviceId: "001", mainboardno: 5, lockno: 6 },
  { BlId: 63, DeviceId: "001", mainboardno: 5, lockno: 7 },
  { BlId: 64, DeviceId: "001", mainboardno: 5, lockno: 8 },
  { BlId: 65, DeviceId: "001", mainboardno: 5, lockno: 9 },
  { BlId: 66, DeviceId: "001", mainboardno: 5, lockno: 10 },
  { BlId: 67, DeviceId: "001", mainboardno: 5, lockno: 11 },
  { BlId: 68, DeviceId: "001", mainboardno: 5, lockno: 12 },
  { BlId: 69, DeviceId: "001", mainboardno: 5, lockno: 13 },
  { BlId: 70, DeviceId: "001", mainboardno: 5, lockno: 14 },
  { BlId: 71, DeviceId: "001", mainboardno: 6, lockno: 1 },
  { BlId: 72, DeviceId: "001", mainboardno: 6, lockno: 2 },
  { BlId: 73, DeviceId: "001", mainboardno: 6, lockno: 3 },
  { BlId: 74, DeviceId: "001", mainboardno: 6, lockno: 4 },
  { BlId: 75, DeviceId: "001", mainboardno: 6, lockno: 5 },
  { BlId: 76, DeviceId: "001", mainboardno: 6, lockno: 6 },
  { BlId: 77, DeviceId: "001", mainboardno: 6, lockno: 7 },
  { BlId: 78, DeviceId: "001", mainboardno: 6, lockno: 8 },
  { BlId: 79, DeviceId: "001", mainboardno: 6, lockno: 9 },
  { BlId: 80, DeviceId: "001", mainboardno: 6, lockno: 10 },
  { BlId: 81, DeviceId: "001", mainboardno: 6, lockno: 11 },
  { BlId: 82, DeviceId: "001", mainboardno: 6, lockno: 12 },
  { BlId: 83, DeviceId: "001", mainboardno: 6, lockno: 13 },
  { BlId: 84, DeviceId: "001", mainboardno: 6, lockno: 14 },
  { BlId: 85, DeviceId: "001", mainboardno: 7, lockno: 1 },
  { BlId: 86, DeviceId: "001", mainboardno: 7, lockno: 2 },
  { BlId: 87, DeviceId: "001", mainboardno: 7, lockno: 3 },
  { BlId: 88, DeviceId: "001", mainboardno: 7, lockno: 4 },
  { BlId: 89, DeviceId: "001", mainboardno: 7, lockno: 5 },
  { BlId: 90, DeviceId: "001", mainboardno: 7, lockno: 6 },
  { BlId: 91, DeviceId: "001", mainboardno: 7, lockno: 7 },
  { BlId: 92, DeviceId: "001", mainboardno: 7, lockno: 8 },
  { BlId: 93, DeviceId: "001", mainboardno: 7, lockno: 9 },
  { BlId: 94, DeviceId: "001", mainboardno: 7, lockno: 10 },
  { BlId: 95, DeviceId: "001", mainboardno: 7, lockno: 11 },
  { BlId: 96, DeviceId: "001", mainboardno: 7, lockno: 12 },
  { BlId: 97, DeviceId: "001", mainboardno: 8, lockno: 1 },
  { BlId: 98, DeviceId: "001", mainboardno: 8, lockno: 2 },
  { BlId: 99, DeviceId: "001", mainboardno: 8, lockno: 3 },
  { BlId: 100, DeviceId: "001", mainboardno: 8, lockno: 4 },
  { BlId: 101, DeviceId: "001", mainboardno: 8, lockno: 5 },
  { BlId: 102, DeviceId: "001", mainboardno: 8, lockno: 6 },
  { BlId: 103, DeviceId: "001", mainboardno: 8, lockno: 7 },
  { BlId: 104, DeviceId: "001", mainboardno: 8, lockno: 8 },
  { BlId: 105, DeviceId: "001", mainboardno: 8, lockno: 9 },
  { BlId: 106, DeviceId: "001", mainboardno: 8, lockno: 10 },
  { BlId: 107, DeviceId: "001", mainboardno: 8, lockno: 11 },
  { BlId: 108, DeviceId: "001", mainboardno: 8, lockno: 12 },
  { BlId: 109, DeviceId: "001", mainboardno: 8, lockno: 13 },
  { BlId: 110, DeviceId: "001", mainboardno: 8, lockno: 14 },
  { BlId: 111, DeviceId: "001", mainboardno: 9, lockno: 1 },
  { BlId: 112, DeviceId: "001", mainboardno: 9, lockno: 2 },
  { BlId: 113, DeviceId: "001", mainboardno: 9, lockno: 3 },
  { BlId: 114, DeviceId: "001", mainboardno: 9, lockno: 4 },
  { BlId: 115, DeviceId: "001", mainboardno: 9, lockno: 5 },
  { BlId: 116, DeviceId: "001", mainboardno: 9, lockno: 6 },
  { BlId: 117, DeviceId: "001", mainboardno: 9, lockno: 7 },
  { BlId: 118, DeviceId: "001", mainboardno: 9, lockno: 8 },
  { BlId: 119, DeviceId: "001", mainboardno: 9, lockno: 9 },
  { BlId: 120, DeviceId: "001", mainboardno: 9, lockno: 10 },
  { BlId: 121, DeviceId: "001", mainboardno: 9, lockno: 11 },
  { BlId: 122, DeviceId: "001", mainboardno: 9, lockno: 12 },
  { BlId: 123, DeviceId: "001", mainboardno: 9, lockno: 13 },
  { BlId: 124, DeviceId: "001", mainboardno: 9, lockno: 14 },
  { BlId: 125, DeviceId: "001", mainboardno: 10, lockno: 1 },
  { BlId: 126, DeviceId: "001", mainboardno: 10, lockno: 2 },
  { BlId: 127, DeviceId: "001", mainboardno: 10, lockno: 3 },
  { BlId: 128, DeviceId: "001", mainboardno: 10, lockno: 4 },
  { BlId: 129, DeviceId: "001", mainboardno: 10, lockno: 5 },
  { BlId: 130, DeviceId: "001", mainboardno: 10, lockno: 6 },
  { BlId: 131, DeviceId: "001", mainboardno: 10, lockno: 7 },
  { BlId: 132, DeviceId: "001", mainboardno: 10, lockno: 8 },
  { BlId: 133, DeviceId: "001", mainboardno: 10, lockno: 9 },
  { BlId: 134, DeviceId: "001", mainboardno: 10, lockno: 10 },
  { BlId: 135, DeviceId: "001", mainboardno: 10, lockno: 11 },
  { BlId: 136, DeviceId: "001", mainboardno: 10, lockno: 12 },
  { BlId: 137, DeviceId: "001", mainboardno: 10, lockno: 13 },
  { BlId: 138, DeviceId: "001", mainboardno: 10, lockno: 14 },
];
async function initDb() {
  for (let i = 0; i < glLockers.length; i++) {
    const locker = glLockers[i];
    const lockerRow = Locker.build({
      BlId: locker["BlId"],
      DeviceId: locker["DeviceId"],
      mainboardno: locker["mainboardno"],
      lockno: locker["lockno"],
    });
    await lockerRow.save();
  }
}
(async () => {
  // await sequelize.sync({ force: true }) //每次重置
  await sequelize.sync(); //存在不操作
  // await sequelize.sync({ alter: true }) //修改才允许重置，每次都修改
  const result = await Locker.findAll({});
  //没有数据才初始化
  if(result.length==0){
    await initDb();
  }
  
})();

// export{Locker} //报错：SyntaxError: Unexpected token 'export'
module.exports={Locker}